package Singleton;

/**
 * @ProjectName: 23种设计模式
 * @Package: Singleton
 * @ClassName: Mgr03
 * @Author: renhan
 * @Description:
 * @Date: 2020/11/10 15:43
 * @Version: 1.0
 *
 * lozy looding
 * 懒汉式
 * 按需求初始化，但是线程不安全
 */
public class Mgr03 {
    private static Mgr03 INSTANCE;
    private Mgr03(){}
    public static Mgr03 getInstance(){
        if (INSTANCE == null){
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            INSTANCE = new Mgr03();
        }
        return INSTANCE;
    }
    public  void m() {System.out.println("m");}

    public static  void main(String[] args){
        for (int i = 0; i < 100; i++){
            new Thread(()->{
                System.out.println(Mgr03.getInstance().hashCode());
            }).start();
        }
    }
}
